/**
 * <p>订单信息</p>
 * 封装axios操作
 * @author  Lyh
 * @since  2023-07-11
 */

import request from '@/utils/request'

/**
 * 分页查询订单信息
 */
export function queryOrderInfo(params) {
  return request.get(
    '/orderInfo/getOrderInfoByPage',
    {
      params: params,
      headers: {
        'Content-Type': 'application/json'
      }
    })
}

/**
 * 根据orderId逻辑删除订单信息
 */
export function deleteOrderInfoById(params) {
  return request.delete(`/orderInfo/deleteOrderById/${params}`)
}

/**
 * 获得全部订单素材场景分类
 */
export function queryTotalLevelOrderCategory() {
  return request({
    url: '/orderDataGathering/gerOrderCategory',
    method: 'get',
  })
}

/**
 * 根据用户id查询该用户可用优惠券
 */
export function queryCustomerCoupon(userId) {
  return request.get(`/customer/getCustomerCoupon/${userId}`)
}

/**
 * 使用优惠券
 */
export function useCustomerCoupon(couponId, orderId) {
  return request.put(`/customer/useCustomerCoupon/${couponId}/${orderId}`)
}

/**
 * 新增订单相关信息
 */
export function insertOrderInfo(data) {
  return request({
    url: '/orderInfo/insertOrderData',
    method: 'post',
    data
  });
}

/**
 * 上传订单图片
 */
export function orderUploadFile(form) {
  return request.post('/orderInfo/uploadFile', form, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }
  );
}

/**
 * 根据订单ID查询订单信息
 */
export function queryOrderInfoById(orderId) {
  return request.get(`/orderInfo/getOrderInfoById/${orderId}`)
}


/**
 * 根据订单ID查询该订单的任务信息
 */
export function queryOrderDetailByOrderId(orderId) {
  return request.get(`/orderInfo/getOrderDetailByOrderId/${orderId}`)
}

/**
 * 获取所有空闲制作人员
 */
export function queryStaffInfo() {
  return request({
    url: '/staff/getStaffInfo',
    method: 'get',
  })
}

/**
 * 新增任务信息
 */
export function insertTaskInfo(data) {
  return request.post('/orderInfo/insertTaskInfo', data)
}

/**
 * 修改任务信息
 */
export function updateTaskInfo(item) {
  let data = {
    id: item.id,
    taskName: item.taskName,
    companyId: item.companyId,
    companyName: item.companyName,
    sceneId: item.sceneId,
    sceneName: item.sceneName,
    gnfl: item.gnfl,
    gnflName: item.gnflName,
    makeType: item.makeType,
    makeId: item.makeId,
    makeName: item.makeName,
    payment: item.money - item.paidMoney,
    money: item.money,
    paidMoney: item.paidMoney
  }
  return request.put('/orderInfo/updateTaskInfo', data)
}

/**
 * 根据taskId逻辑删除任务信息
 */
export function deleteOrderDetailById(taskId) {
  return request.delete(`/orderInfo/deleteOrderTask/${taskId}`)
}

/**
 * 订单支付尾款
 */
export function orderPayMoney(data) {
  return request.put('/orderInfo/payMoneyAboutOrder', data)
}

/**
 * 任务支付尾款
 */
export function taskPayMoney(data) {
  return request.put('/orderInfo/payMoneyAboutTask', data)
}

/**
 * 修改订单和任务信息
 */
export function updateOrderAndTask(data) {
  return request.put('/orderInfo/updateOrderAndTask', data)
}

